package com.xiaoxu.intranetweb.mybatisplusSzappdb.controller.compete;

import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.JSONObject;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.business.compete.CompeteDetailBu;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.dao.UserInfoDao;
import com.xiaoxu.intranetweb.util.PermissionCheck;
import com.xiaoxu.intranetweb.util.SzResult;
import com.xiaoxu.intranetweb.util.WebFunctionUtil;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.swing.text.html.Option;
import java.util.Map;
import java.util.Optional;

@RestController
@RequestMapping(value = "/competeDetail")
public class CompeteDetailController {
    @Autowired
    private CompeteDetailBu competeDetailBu;
    @Autowired
    private UserInfoDao userInfoDao;
    @Autowired
    private WebFunctionUtil webFunctionUtil;

    //查询竞争详情表控制层
    @GetMapping("/getCompeteDetail")
    public SzResult getCompeteDetail(@RequestParam(required = false) String id,
                                     @RequestParam(required = false) String competeId, HttpServletRequest request) {
        String plantId = request.getHeader("Plant-Id");
        return competeDetailBu.getCompeteDetail(id, competeId, plantId);
    }

    //新增竞争详情表控制层
    @PostMapping("/addCompeteDetail")
    @PermissionCheck("competeDetail_addCompeteDetail")
    public SzResult addCompeteDetail(@RequestBody JSONObject jsonObject, HttpServletRequest request) throws Exception {
        String competeId = jsonObject.getString("competeId");
        String pdtId = jsonObject.getString("pdtId");
        String pdtWeight = jsonObject.getString("pdtWeight");
        String pdtPrice = jsonObject.getString("pdtPrice");
        String minBid = jsonObject.getString("minBid");
        String token = request.getHeader("Authorization");
        String plantId = request.getHeader("Plant-Id");
        return competeDetailBu.addCompeteDetail(competeId, pdtId, pdtWeight, pdtPrice, minBid, token, plantId);
    }

    //删除竞争详情表控制层
    @GetMapping("/deleteCompeteDetail")
    @PermissionCheck("competeDetail_deleteCompeteDetail")
    public SzResult deleteCompeteDetail(@RequestParam String id, HttpServletRequest request) throws Exception {
        String token = request.getHeader("Authorization");
        String plantId = request.getHeader("Plant-Id");
        return competeDetailBu.delCompeteDetail(id, plantId);
    }

    //修改竞争详情表控制层
    @PostMapping("/updateCompeteDetail")
    @PermissionCheck("competeDetail_updateCompeteDetail")
    public SzResult updateCompeteDetail(@RequestBody JSONObject jsonObject, HttpServletRequest request) throws Exception {
        String id = jsonObject.getString("id");
        String competeId = jsonObject.getString("competeId");
        String pdtId = jsonObject.getString("pdtId");
        String pdtWeight = jsonObject.getString("pdtWeight");
        String minBid = jsonObject.getString("minBid");
        String pdtPrice = jsonObject.getString("pdtPrice");
        String token = request.getHeader("Authorization");
        String plantId = request.getHeader("Plant-Id");
        return competeDetailBu.updateCompeteDetail(id, competeId, pdtId, pdtWeight, pdtPrice, minBid, token, plantId);
    }
}
